* In-text numbers in subsubsection VI.D and Figure VIII
* 29 Oct 2021

clear all
set more off

grstyle init
grstyle set plain, nogrid horizontal
grstyle color background white

*Choose figure width:
local fig_w= 5
local res = `fig_w' * 600
	

import excel "$output_s/Structural_Results_at_ss_assets_minus_land_of_rich.xlsx", sheet("Sheet1") firstrow clear 


* Figure VIII

gen occup_opt = ceil(case_opt/2) //Quick way to separate cases
gen occup_bl = ceil(case_bl/2)

label define occupation 1 "Mixing" 2 "Livestock Rearing Only" 3 "Wage Work Only" 4 "No Work"
label values occup* occupation

preserve
	replace occup_bl = . if occup_bl == 4
	keep hhid occup*
	rename occup_opt occup2
	rename occup_bl occup1
	reshape long occup, i(hhid) j(tag)
	label define tags 1 "Actual" 2 "Optimal"
	label values tag tags
	
	*Colored version
	catplot tag occup, percent(tag) var1opts(label(labsize(small))) var2opts(label(labsize(small))) recast(bar) asyvars bargap(20) bar(1, color(pink*0.4)) bar(2, color(green*0.4)) ytitle("Percentage") name(bars_bl, replace)
	graph save bars_bl "$output/Bars_cases_bl_vs_opt.gph", replace
	graph export "$output/Bars_cases_bl_vs_opt.png", as(png) replace 
	
	*TIFF grayscale version
	catplot tag occup, percent(tag) var1opts(label(labsize(small))) var2opts(label(labsize(small))) recast(bar) asyvars bargap(20) bar(1, color(gs5)) bar(2, color(gs10)) ytitle("Percentage") name(bars_bl, replace) xsize(`fig_w')
	graph export "$output/TIFF/Bars_cases_bl_vs_opt.tif", as(tif) replace  width(`res')
restore


* Numbers in text

preserve
	log using "$output/misallocation.log", replace

	tab occup_bl
	tab occup_bl if occup_bl != 4

	tab occup_opt

	quietly: gen misd = misallocation > 0
	tab misd
	
	su misallocation, d
	disp r(sum)/18.46 // Using exchange rate 18.46 BDT = 1 USD

	su min_transfer, d
	disp r(sum)/18.46

	log close
restore